package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.Settlement;
import com.ruoyi.business.service.SettlementService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.SysDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 结算Controller
 * 
 * @author xx
 * @date 2020-04-03
 */
@Controller
@RequestMapping("/business/settlement")
public class SettlementController extends BaseController {
    private String prefix = "business/settlement";

    @Autowired
    private SettlementService settlementService;
    @Autowired
    private SysDictDataService sysDictDataService;

    @RequiresPermissions("business:settlement:view")
    @GetMapping()
    public String settlement() {
        return prefix + "/settlement";
    }

    /**
     * 查询结算列表
     */
    @RequiresPermissions("business:settlement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Settlement settlement) {
        startPage();
        if (!SysUser.isAdmin(ShiroUtils.getUserId())) {
            settlement.setUserId(ShiroUtils.getUserId());
        }
        List<Settlement> list = settlementService.selectSettlementList(settlement);
        return getDataTable(list);
    }

    /**
     * 导出结算列表
     */
    @RequiresPermissions("business:settlement:export")
    @Log(title = "结算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Settlement settlement) {
        List<Settlement> list = settlementService.selectSettlementList(settlement);
        ExcelUtil<Settlement> util = new ExcelUtil<>(Settlement.class);
        return util.exportExcel(list, "结算数据", sysDictDataService.selectAll(Settlement.class));
    }

    /**
     * 新增结算
     */
    /*@GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }*/

    /**
     * 新增保存结算
     */
    /*@RequiresPermissions("business:settlement:add")
    @Log(title = "结算", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Settlement settlement) {
        return toAjax(settlementService.insertSettlement(settlement));
    }*/

    /**
     * 修改结算
     */
    /*@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Settlement settlement = settlementService.selectSettlementById(id);
        mmap.put("settlement", settlement);
        return prefix + "/edit";
    }*/

    /**
     * 修改保存结算
     */
    /*@RequiresPermissions("business:settlement:edit")
    @Log(title = "结算", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Settlement settlement) {
        return toAjax(settlementService.updateSettlement(settlement));
    }*/

    /**
     * 删除结算
     */
    /*@RequiresPermissions("business:settlement:remove")
    @Log(title = "结算", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(settlementService.deleteSettlementByIds(ids));
    }*/
}
